<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" enctype="multipart/form-data" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">公众号设置</div>
                            </div>
                            <div class="am-form-group">
                                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                                    <legend>图片上传</legend>
                                </fieldset>

                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" id="uploadImage">上传图片</button>
                                    <div class="layui-upload-list">
                                        <img class="layui-upload-img" id="image" src="<?=$model['attention_code']?>" width="200px">
                                        <input name="wxapp[attention_code]" id="payment_code" hidden value="<?=$model['attention_code']?>"/>
                                    </div>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<link rel="stylesheet" href="assets/layui/css/layui.css" media="all">
<script src="assets/layui/layui.js" charset="utf-8"></script>


<script src="assets/store/js/app.js"></script>
<script src="assets/store/js/file.library.js"></script>
<script>
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#uploadImage'
            , url: '/store/upload/image_1' //改成您自己的上传接口
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#image').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                console.log(res);
                //如果上传失败
                if (res.code == 0) {
                    return layer.msg('上传失败');
                } else if (res.code == 1) {
                    $('#payment_code').val(res.data.file_path);
                    return layer.msg("上传成功");
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });

    $(function () {
        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();

    });
</script>
